let timer
export default function ajax(params, conetntType) {
  const baseUrl = "https://www.dunlian.xyz:8443/dl"
  // timer=setTimeout(v=>{
  //   wx.showLoading({
  //     title: '正在加载中',
  //   })
  // },1000)
  return new Promise((resolve, reject) => {
    console.log(params.url + "请求参数：" + "------->" , params.data);
    wx.request({
      ...params,
      url: baseUrl + params.url,
      header: {
        'content-type': conetntType || 'application/x-www-form-urlencoded'
      },
      success: (data) => {
        console.log(params.url + "返回参数：" + "------->" , data.data);
        let res = data.data
        if (res.code != 200 && params.url!='/demandApply/delivery') {
          wx.showModal({
            title: '温馨提示',
            showCancel: false,
            content: res.msg
          })
        }
        resolve(data.data)
      },
      fail: (err) => {
        clearTimeout(timer)
        wx.showToast({
          title: '资源加载失败',
          icon: "none"
        })
        wx.hideLoading({
          success: (res) => {},
        })
        reject(err)
      }
    })
  })
}

// 上传文件地址
export const fileUrl = "https://www.dunlian.xyz:8443/dl/api/reimbursed/uploadFile"